#ifndef LOCKER_H_
#define LOCKER_H_

#include <windows.h>


class CriticalSection
{
public:
    CriticalSection() {
        InitializeCriticalSection(&_cs);
    }

    ~CriticalSection() {
        DeleteCriticalSection(&_cs);
    }

    void lock() {
        EnterCriticalSection(&_cs);
    }

    void unlock() {
        LeaveCriticalSection (&_cs);
    }

private:
    CRITICAL_SECTION _cs;
};


class Lock
{
public:
    Lock(CriticalSection& cs) :_cs(cs) {
        _cs.lock();
    }

    Lock(const CriticalSection& cs) :_cs(const_cast<CriticalSection&>(cs)) {
        _cs.lock();
    }

    ~Lock() {
        _cs.unlock();
    }

private:
    CriticalSection& _cs;
};


#endif //LOCKER_H_